﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

// Added
using GELib;
using System.Xml;
using System.IO;

namespace GameEditor
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {


        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            // Load configuration
            GEConfig.loadConfig();

            // Load lang phrases
            LangManager.langLoaded += new EventHandler(changeWindowLanguage);
            LangManager.loadLanguage(GEConfig.defaultLanguage);
           
            // initialize project dependency
            GEProject.projectOpened += new EventHandler(projectOpened);
            GEProject.projectClosed += new EventHandler(projectClosed);
        }

        void projectClosed(object sender, EventArgs e)
        {
            this.Title = "Game Editor";
        }

        void projectOpened(object sender, EventArgs e)
        {
            this.Title = "Game Editor - " + GEProject.Title + " - version " + GEProject.Version;
        }

        private void changeWindowLanguage(object sender, EventArgs e)
        {
            // Menu bar
            miFile.Header = LangManager.getPhrase("mBar_File");
            miEdit.Header = LangManager.getPhrase("mBar_Edit");
            miCancel.Header = LangManager.getPhrase("mBar_Edit_Cancel");
            miCut.Header = LangManager.getPhrase("mBar_Edit_Cut");
            miPaste.Header = LangManager.getPhrase("mBar_Edit_Paste");
            //miCopy.Header = LangManager.getPhrase("mBar_Edit_Copy");

            miProject.Header = LangManager.getPhrase("mBar_Project");
            miNewProject.Header = LangManager.getPhrase("mBar_Project_NewProject");
            miLoadProject.Header = LangManager.getPhrase("mBar_Project_LoadProject");
            miCloseProject.Header = LangManager.getPhrase("mBar_Project_CloseProject");
            miSave.Header = LangManager.getPhrase("mBar_Project_SaveProject");
            miInfos.Header = LangManager.getPhrase("mBar_Project_ProjectInfos");

            miTools.Header = LangManager.getPhrase("mBar_Tools");
            miOptions.Header = LangManager.getPhrase("mBar_Tools_Options");

            miAbout.Header = LangManager.getPhrase("mBar_About");

            // other
        }

        #region "Menu bar events responding"
        private void miNewProject_Click(object sender, RoutedEventArgs e)
        {
            dlg_NewProject NP = new dlg_NewProject();
            NP.Owner = this;
            NP.ShowDialog();
            
        }
        private void miLoadProject_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
            ofd.DefaultExt = ".GEPj";
            ofd.Multiselect = false;
            ofd.ShowDialog();
            
            // Check file
            FileInfo projectFile = new FileInfo(ofd.FileName);
            if (projectFile.Extension != ".GEPj")
                MessageBox.Show(LangManager.getPhrase("err_WrongProjectFormat"));
            else
                GEProject.openProject(projectFile.FullName);
        }
        private void miCloseProject_Click(object sender, RoutedEventArgs e)
        {
            GEProject.closeProject();
        }

        private void miOptions_Click(object sender, RoutedEventArgs e)
        {
            dlg_Options dO = new dlg_Options();
            dO.Owner = this;
            dO.ShowDialog();
            if ((bool)dO.DialogResult)
            {
                LangManager.loadLanguage("Lang/En-En.xml");
            }

        }

        #endregion



       


    }
}
